/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.machineryrental.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author David Katuscak, 359273
 */
@Entity
public class Machine implements Serializable {
    
    @OneToMany(mappedBy = "machine", fetch = FetchType.LAZY)
    private List<Rental> rentals;

    @Id
    @GeneratedValue
    private long id;
    
    @Column(nullable=false, unique=true)
    private String code;
    
    @Column(nullable=false)
    private String brand;
    
    @Column(nullable=false)
    private String model;
    
    @Temporal(TemporalType.DATE)
    private Date yearOfProduction;
    
    @OneToMany(mappedBy = "machine", fetch = FetchType.LAZY)
    private List<Revision> revisions = new ArrayList<Revision>();

    public long getId() {
        return this.id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public Date getYearOfProduction() {
        return yearOfProduction;
    }

    public void setYearOfProduction(Date yearOfProduction) {
        this.yearOfProduction = yearOfProduction;
    }

    public List<Revision> getRevisions() {
        return revisions;
    }

    public void setRevisions(List<Revision> revisions) {
        this.revisions = revisions;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (int) (this.id ^ (this.id >>> 32));
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Machine other = (Machine) obj;
        if (this.id != other.id) {
            return false;
        }
        if (!this.code.equals(other.code)) {
            return false;
        }
        if (!this.brand.equals(other.brand)) {
            return false;
        }
        if (!this.model.equals(other.model)) {
            return false;
        }
        
        return true;
    }

    @Override
    public String toString() {
        return "Machine [machineId=" + this.id + ", code=" + code
                + ", brand=" + brand + ", model=" + model
                + ", yearOfProduction=" + yearOfProduction
                + ", revisions size=" + revisions.size() + "]";
    }
}
